package com.cx.mall.common.util;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import java.io.Serializable;
@Getter
@Setter
@ToString
public class ResponseVo<T> implements Serializable {
    private static final long serialVersionUID = 1L;
    private T data;
    private String msg;
    private int code;

    public ResponseVo() {
    }

    public ResponseVo(String message) {
        this.code = ResponseEnum.SUCCESS.getCode();
        this.msg = message;
    }

    public ResponseVo(T data, String msg, int code) {
        this.data = data;
        this.msg = msg;
        this.code = code;
    }




    public ResponseVo(T data, ResponseEnum responseEnum) {
        this.data = data;
        this.msg = responseEnum.getMessage();
        this.code = responseEnum.getCode();
    }

    public ResponseVo(ResponseEnum responseEnum) {
        this.msg = responseEnum.getMessage();
        this.code = responseEnum.getCode();
    }

    public ResponseVo(T data) {
        this.data = data;
    }
    public static <T> ResponseVo<T> success(T data) {
        return new ResponseVo<>(data, ResponseEnum.SUCCESS);
    }
    public static <T> ResponseVo<T> success() {
        return new ResponseVo<>(ResponseEnum.SUCCESS);
    }
    public static <T> ResponseVo<T> success(String message) {

        return new ResponseVo<>(message);
    }

    public static <T> ResponseVo<T> fail(ResponseEnum responseEnum) {
        return new ResponseVo<>(responseEnum);
    }
    public static <T> ResponseVo<T> fail(T data, ResponseEnum responseEnum) {
        return new ResponseVo<>(data, responseEnum);
    }

    public static <T> ResponseVo<T> fail(String message) {

        return new ResponseVo<>(message);
    }




}
